<?php
/**
 * Plugin to set metadata (title/keywords/description) automaticly. This data could be set in
 * admin area. This data is taken from database (PREFIX_pages table)
 * 
 * @author Konstantin Shamko <konstantin.shamko@gmail.com> 
 * @version 0.0.1
 * @copyright  Copyright (c) 2009 Konstantin Shamko
 * @category VaselinEngine
 * @package Content Module
 * @subpackage Helper
 * @license  New BSD License
 *
 */
class Helpers_Content_TitlePlugin extends Zend_Controller_Plugin_Abstract {	
	
	/**
	 * Is called before dispatching. Sets title/keyword/description to a page automaticly.
	 * This data could be overrided in cantrollers use Bel_Seo class to set new 
	 * title/desciption/keywords if you need.
	 *
	 * @param Zend_Controller_Request_Abstract $request
	 * @return void
	 */
	public function postDispatch(Zend_Controller_Request_Abstract $request){
		$seo = Bel_Seo::getInstance();
		
		if($request->getModuleName()==='admin'){
			$titles = new Zend_Config_Ini(HOME_DIR.'config/admin_titles.ini','production');
			$keyName = $request->getControllerName().'_'.$request->getActionName();
			$title = ($titles->$keyName)?$titles->$keyName:$keyName;
			$seo->setTitle($title); 
		}else{
			$pages = new Models_Content_Pages();
			$page = $pages->getCurrentPage();
			if($page){
				$seo->setTitle($page->page_title);
				$seo->setDescription($page->page_description);
				$seo->setKeywords($page->page_keywords);
			}
		}
	}
}